package me.ereach.multi;

import java.util.ArrayList;
import java.util.List;

public class Main02ThreadPause3 {
    public static void main(String[] args) {
        List<Thread> threads = new ArrayList<>();

        for (var i = 0; i < 5; i++) {
            Thread thread = new Thread(() -> {
                System.out.println(Thread.currentThread().getName() + " started");
                try {
                    Thread.sleep(3000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                finally {
                    System.out.println(Thread.currentThread().getName() + " finished");
                }
            });
            threads.add(thread);
            thread.start();
        }

        for (var thread : threads) {
            try {
                thread.join();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }

        System.out.println("All threads are completed");
    }
}
